package com.wtpaint.algorithm.sort;

import com.wtpaint.algorithm.SortUtil;

import java.util.Arrays;

public class InsertionSort2 {

    private InsertionSort2() {
    }

    public static void sort(Comparable[] arr) {
        int n = arr.length;
        for (int i = 0; i < n; i++) {
            Comparable e = arr[i];
            int j;
            for (j = i; j > 0 && arr[j - 1].compareTo(e) > 0; j--) {
                arr[j] = arr[j - 1];
            }
            arr[j] = e;
        }
    }

    public static void main(String[] args) {
        int n = 100000;
        Integer[] arr1 = SortUtil.generateRandomArray(n, 0, 10);
        Integer[] arr2 = Arrays.copyOf(arr1, arr1.length);
        SortUtil.testSort("com.wtpaint.algorithm.sort.SelectionSort", arr1);
        SortUtil.testSort("com.wtpaint.algorithm.sort.InsertionSort2", arr2);
    }
}
